import copy

import pandas as pd


class Output:
    __name = 'Output'

    ''' 打印图（集合） '''

    @staticmethod
    def print_graph_set(g=None):
        if g is None:
            return
        print('点集：')
        print('\t{0}'.format(g[0]))
        print('边集：')
        for key, value in g[1].items():
            print('\t边：{0}，权重：{1}'.format(key, value))
        return

    ''' 打印二部图（集合） '''

    @staticmethod
    def print_bipartite_graph(g=None):
        if g is None:
            return
        print('点集1：')
        print('\t{0}'.format(g[0][0]))
        print('点集2：')
        print('\t{0}'.format(g[0][1]))
        print('边集：')
        for key, value in g[1].items():
            print('\t边：{0}，权重：{1}'.format(key, value))
        return

    ''' 打印图（邻接矩阵） '''

    @staticmethod
    def print_graph_matrix(g=None, l_index=None, c_index=None):
        if g is None:
            return
        v_set = g[0]  # 图的点集
        s_set = g[1]  # 图的边集

        df = pd.DataFrame(s_set, index=v_set, columns=v_set)
        if l_index is not None:
            df = df.iloc[l_index:l_index + 1, :]
        if c_index is not None:
            df = df.iloc[:, c_index: c_index + 1]

        print(df)

    ''' 打印二部图（邻接矩阵） '''

    @staticmethod
    def print_bipartite_graph_matrix(g=None, l_index=None, c_index=None):
        if g is None:
            return
        v_set1 = g[0][0]
        v_set2 = g[0][1]  # 图的点集
        s_set = g[1]  # 图的边集

        df = pd.DataFrame(s_set, index=v_set1, columns=v_set2)
        if l_index is not None:
            df = df.iloc[l_index:l_index + 1, :]
        if c_index is not None:
            df = df.iloc[:, c_index: c_index + 1]

        print(df)

    ''' 打印l等子图（邻接矩阵） '''

    @staticmethod
    def print_bipartite_subgraph_matrix(g=None, l_index=None, c_index=None, marks=None):
        if g is None:
            return
        g = copy.deepcopy(g)
        v_set1 = g[0][0]
        v_set2 = g[0][1]  # 图的点集
        s_set = g[1]  # 图的边集

        v_set1_mark = marks[0]  # v_set1的顶标
        v_set2_mark = marks[1]  # v_set2的顶标

        for v1_index in range(len(v_set1)):
            for v2_index in range(len(v_set2)):
                m = v_set1_mark[v1_index] + v_set2_mark[v2_index]
                if s_set[v1_index][v2_index] != m:
                    s_set[v1_index][v2_index] = 0

        df = pd.DataFrame(s_set, index=v_set1, columns=v_set2)
        if l_index is not None:
            df = df.iloc[l_index:l_index + 1, :]
        if c_index is not None:
            df = df.iloc[:, c_index: c_index + 1]

        print(df)

    ''' 打印匹配 '''

    @staticmethod
    def print_match(match=None):
        if match is None:
            return
        string = []
        for key, value in match.items():
            string.append(key + value)
        print(string)
